package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.Toast;

import com.example.myapplication.Adapter.RecyclerViewAdapter;
import com.example.myapplication.Model.RecyclerViewModel;

import java.util.ArrayList;
import java.util.List;

public class RecyclerViewActivity extends AppCompatActivity implements RecyclerViewAdapter.OnItemClickListener {

    private List<RecyclerViewModel> modelList = new ArrayList<>();
    private RecyclerView mRecyclerView;
    private RecyclerViewAdapter mAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recycler_view);

        for (int i = 0; i < 100; i++) {
            RecyclerViewModel model = new RecyclerViewModel();
            String string  = new String("RecyclerVIew " + i);
            model.setName(string);
            modelList.add(model);
        }
        mAdapter = new RecyclerViewAdapter(modelList, this);
        mAdapter.setOnItemClickListener(this);
        mRecyclerView = findViewById(R.id.rv);
        mRecyclerView.setAdapter(mAdapter);
        // 线性布局
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        // 网格布局
        GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 3);
        // 瀑布流
        StaggeredGridLayoutManager staggeredGridLayoutManager =
                new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL);
        mRecyclerView.setLayoutManager(staggeredGridLayoutManager);
    }

    @Override
    public void OnItemClick(int position) {
        Toast.makeText(this, "这是第" + position + "个item", Toast.LENGTH_SHORT).show();
    }
}